package com.dogdog.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.toolbox.StringRequest;
import com.dogdog.bean.Location;
import com.dogdog.bean.LocationListInfo;
import com.dogdog.bean.LoginDataBean;
import com.dogdog.bean.MarkerInfo;
import com.dogdog.bean.MarkerListInfo;
import com.dogdog.bean.Me;
import com.dogdog.bean.Status;
import com.dogdog.manager.C;
import com.dogdog.manager.MyApplication;
import com.google.gson.Gson;

public class LocationUtil {
	private Gson gson;
	private Context context;

	/**
	 * 构造函数
	 */
	public LocationUtil(Context context) {
		this.context = context;
	}

	/**
	 * 保存经纬度到服务器数据库
	 */
	public void saveLocation(final int uid, double mLatitude, double mLongtitude) {
		final String str_latitude = Double.toString(mLatitude);
		final String str_longtitude = Double.toString(mLongtitude);
		StringRequest saveUserLocation = new StringRequest(Method.POST,
				C.URL.MarkerLocation, new Response.Listener<String>() {

					@Override
					public void onResponse(String response) {
						gson = new Gson();
						Status s = gson.fromJson(response.toString(),
								Status.class);
						if (s.getState() == 1) {
							Toast.makeText(context, "保存location成功",
									Toast.LENGTH_SHORT).show();
						}
					}
				}, new Response.ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						// TODO Auto-generated method stub
						Toast.makeText(context, "保存location失败",
								Toast.LENGTH_SHORT).show();
					}
				}) {
			@Override
			protected Map<String, String> getParams() throws AuthFailureError {
				Map<String, String> param = new HashMap<String, String>();
				param.put("uid", String.valueOf(uid));
				param.put("Latitude", str_latitude);
				param.put("Longtitude", str_longtitude);
				return param;
			}
		};
		MyApplication.getHttpQueue().add(saveUserLocation);

	}
	


}
